<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册页面</title>
    <link rel="stylesheet" href="css/conmmon.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery.min.js"></script>
</head>

<body>
    <!-- 导航栏 -->
    <div class="nav">
        <img src="image/happy.jpg" alt="">
        <span class="title">我的博客系统</span>
        <!-- 用来占据中间位置 -->
        <span class="spacer"></span>

        <!-- <a href="#">注销</a> -->
    </div>
    <!-- 版心 -->
    <div class="login-container">
        <!-- 中间的注册框 -->
        <div class="login-dialog">
            <h3>注册</h3>
            <!--todo:使用form表单来进行登陆就很好-->
            <form action="/user/reg" method="POST" id="form1" enctype="multipart/form-data">
                <div class ="row">
                    <span>提交头像</span>
                    <input type="file" id="jpgfile" name="jpgfile">
                </div>
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username" name="username">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" id="password" name="password">
            </div>
                <div class ="row">
                    <span>gitee地址</span>
                    <input type="text" id="address" name="address">
                </div>
            <div class="row">
                <span>确认密码</span>
                <input type="password" id="password2">
            </div>
            </form>
            <div class="row">
                <button type="submit" id="submit">提交</button>
            </div>
        </div>
    </div>
</body>
<script>
    $("#submit").click(
        function (){
            var form = document.getElementById("form1");
            var file = new FormData(form);
            var username=jQuery("#username");
            var password=jQuery("#password");
            var password2=jQuery("#password2");
            var address=jQuery("#address");
            if(username.val() == ""){
                alert("请输入用户名");
                username.focus();
                return false;
            }
            if(password.val() == ""){
                alert("请输入密码");
                password.focus();
                return false;
            }
            if(password2.val() == ""){
                alert("请确认密码");
                password2.focus();
                return false;
            }
            if(address.val() == ""){
                alert("请输入gitee地址");
                address.focus();
                return false;
            }
            if(password.val() != password2.val()){
                alert("两次密码输入不一致")
                password2.focus();
                return false;
            }
            $.ajax({
                type: 'POST',
                url: "/user/reg",
                data: file,
                cache: false,
                processData: false,
                contentType: false,
                success: function (result){
                    if(result.code==200 &&result.data!=null){
                        alert("注册成功！即将返回登陆页面");
                        location.href="login.html"
                    }else{
                        alert("请重试");
                    }
                }
            });
        }

    );

</script>

</html>